﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyCommerce.Presentation.Stores.IViews;
using MyCommerce.Business.Stores;
using MyCommerce.Business.GeneralParameters;
using Innova.Microfinanzas.BusinessEntities.EnumClassifierTypes;

namespace MyCommerce.Presentation.Stores.Presenters
{
    public class CashInOutFlowsPresenter
    {
        private ICashInOutFlowsView pViewToPresent;

        public CashInOutFlowsPresenter(ICashInOutFlowsView vView)
        {
            pViewToPresent = vView;
            pViewToPresent.OnCancel += new EventHandler(pViewToPresent_OnCancel);
            pViewToPresent.OnDelete += new EventHandler(pViewToPresent_OnDelete);
            pViewToPresent.OnLoadData += new EventHandler(pViewToPresent_OnLoadData);
            pViewToPresent.OnLoadView += new EventHandler(pViewToPresent_OnLoadView);
            pViewToPresent.OnNew += new EventHandler(pViewToPresent_OnNew);
            pViewToPresent.OnSave += new EventHandler(pViewToPresent_OnSave);
        }

        private void pViewToPresent_OnSave(object sender, EventArgs e)
        {
            CashInOutFlowsManager cashMgr = new CashInOutFlowsManager();
            cashMgr.CashInOutFlowsInsert(pViewToPresent.Get());
            pViewToPresent.ClearView();
            pViewToPresent.EnableView(false);
            LoadListToView(pViewToPresent.DateSelect);
        }

        private void pViewToPresent_OnNew(object sender, EventArgs e)
        {
            pViewToPresent.EnableView(true);
        }

        private void pViewToPresent_OnLoadView(object sender, EventArgs e)
        {
            DealerStoreManager storeMgr = new DealerStoreManager();
            CommonClassifierManager commonMgr = new CommonClassifierManager();
            pViewToPresent.ColMoneys = commonMgr.GetClassifierByIDType(Convert.ToInt64(CommonClassifierTypes.CurrencyClassfier), true);
            pViewToPresent.ColStores = storeMgr.GetDealerStoresActives();
            LoadListToView(pViewToPresent.DateSelect);
        }

        private void LoadListToView(DateTime dateSelect)
        {
            CashInOutFlowsManager cashMgr = new CashInOutFlowsManager();
            pViewToPresent.ColListData = cashMgr.GetListByDate(dateSelect);
        }

        private void pViewToPresent_OnLoadData(object sender, EventArgs e)
        {
            LoadListToView(pViewToPresent.DateSelect);
        }

        private void pViewToPresent_OnDelete(object sender, EventArgs e)
        {
            CashInOutFlowsManager cashMgr = new CashInOutFlowsManager();
            cashMgr.CashInOutFlowsDelete(pViewToPresent.ObjItemSelect.IdCashInOutFlows);
            LoadListToView(pViewToPresent.DateSelect);
        }

        private void pViewToPresent_OnCancel(object sender, EventArgs e)
        {
            pViewToPresent.ClearView();
            pViewToPresent.EnableView(false);
        }
    }
}
